package com.project.demo.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.demo.entity.Product;

import com.project.demo.entity.Useproduct;
import com.project.demo.mapper.UseproductMapper;
import com.project.demo.service.UseproductService;
import com.project.demo.service.editproductService;
import com.project.demo.vo.AlluseproductVo;
import com.project.demo.vo.useproductVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.List;

@Service
public class UseproductServiceImpl implements UseproductService {
    @Autowired
    private UseproductMapper useproductmapper;

    @Override
    public useproductVo<AlluseproductVo> FinduseproductVo(Integer page, Integer limit) {
        useproductVo useproductVo = new useproductVo();
        useproductVo.setCode(0);
        useproductVo.setMsg("");
        IPage<Useproduct> useproductIPage = new Page<>(page, limit);
        IPage<Useproduct> result = useproductmapper.selectPage(useproductIPage, null);
        useproductVo.setCount(result.getTotal());
        List<Useproduct> useproductList = result.getRecords();
        List<AlluseproductVo> alluseproductVoList = new ArrayList<>();
        for (Useproduct useproduct1 : useproductList) {
            AlluseproductVo alluseproductVo = new AlluseproductVo();
            BeanUtils.copyProperties(useproduct1, alluseproductVo);
            alluseproductVoList.add(alluseproductVo);
        }
        useproductVo.setData(alluseproductVoList);
        return useproductVo;
    }

    @Override
    public useproductVo<AlluseproductVo> FindAlluseproductVo() {
        useproductVo useproductVo = new useproductVo();
        useproductVo.setCode(0);
        useproductVo.setMsg("");
        useproductVo.setCount(Long.valueOf(useproductmapper.selectCount(null)));
        List<Useproduct> useproductList = useproductmapper.selectList(null);
        List<AlluseproductVo> alluseproductVoList = new ArrayList<>();
        for (Useproduct useproduct1 : useproductList) {
            AlluseproductVo alluseproductVo = new AlluseproductVo();
            BeanUtils.copyProperties(useproduct1, alluseproductVo);
            alluseproductVoList.add(alluseproductVo);
        }
        useproductVo.setData(alluseproductVoList);
        return useproductVo;
    }
    @Override
    public Integer deletevo(Integer id) {
        return useproductmapper.deleteVo(id);
    }
    @Override
    public Integer insertvo(Integer id, String sname, String sperson, String speople, String zczt, String sbegint, String scondition) {
        return useproductmapper.insertVo(id,sname,sperson,speople,zczt, sbegint, scondition);
    }

}
